package cn.edu.ctbu.test.service.impl;


import cn.edu.ctbu.test.domain.Course;
import cn.edu.ctbu.test.dao.CourseRepository;
import cn.edu.ctbu.test.domain.Student;
import cn.edu.ctbu.test.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseRepository courseRepository;

    @Override
    public List<Course> findAll() {

        return courseRepository.findAll();
    }

    @Override
    public Page<Course> findAll(Example<Course> course, Pageable pageable){

        return courseRepository.findAll(course,pageable);
    }


    public List<Course> findByName(String courseName) {

        return courseRepository.findByCourseName(courseName);

    }

    public Course insert(Course course) {

        return courseRepository.save(course);
    }

    public void delete(Long courseId) {
        Course course = new Course();
        course.setCourseId(courseId);
        courseRepository.delete(course);
    }

    public Course getById(Long courseId) {

        Course course = courseRepository.findById(courseId).orElse(null);

        return course;
    }

    public Course update(Course course) {

        return courseRepository.save(course);
    }


    public Page<Course> findAll(Pageable pageable) {

        return courseRepository.findAll(pageable);

    }
    
    public List<Course> findByCourseName(String courseName){
        
        return courseRepository.findByCourseName(courseName);
    }


}
